home *** CD-ROM | disk | FTP | other *** search
- Path: Rezonet.net!news
- From: ray@ultimate-tech.com (Ray Dunn)
- Newsgroups: comp.lang.c
- Subject: Re: Newbie - I'm stuck
- Date: 28 Jan 1996 21:11:02 GMT
- Organization: Ultimate Technographics Inc.
- Message-ID: <4egop6$bn0@ns.RezoNet.NET>
- References: <mhoward-2701961816570001@port6.sniff.smallmedia.com>
- NNTP-Posting-Host: 204.19.230.7
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.7
-
- In referenced article, Mark Howard says...
- >I'm stuck.
-
- The problem is in mixing types int and long.
-
- num is a long, and yet you are masking it with (1 << bitCntr) an int
- expression, and I assume ints are sixteen bits of your machine. When
- bitCntr is bigger than 15, the above will alwys give you zero.
-
- Ensure that all your expressions are long, and the program will work.
-
- If you make all your variables long, remember to change the format
- string in the printf statement.
-
- > halfbyt[cntr1] = NULL;
-
- You probably got a warning on this line (or would have if you had the
- correct warning level set). NULL should only be used to initialize
- *pointers*. Use 0 to initialize integer values. (Many compiler don't
- differentiate between 0 and NULL, but most modern ones define NULL as
- ((void *) 0).
-
- Instead of scanning the number bit by bit, why don't you rewrite your
- loop to handle the number 4bits at a time - that's what your trying to
- achieve:
-
- for (i = 0; i < 8; i++)
- {
- halfbyte[i] = (char)(num & 0xF);
- num = num >> 4;
- }
-
- --
- Ray Dunn (opinions are my own) | Phone: (514) 938 9050
- Montreal | Phax : (514) 938 5225
- ray@ultimate-tech.com | Home : (514) 630 3749
-
-